package org.openintents.droidcon.cloud.mvc;

import org.openintents.droidcon.cloud.model.Panel;
import org.openintents.droidcon.cloud.model.Schedule;
import org.openintents.droidcon.cloud.model.Slot;

public class SlotForm {

	private Slot editSlot = null;
	private Schedule schedule = null;
	private Panel panel = null;

	public SlotForm(Schedule schedule, Panel panel, Slot editSlot) {
		if (editSlot != null) {
			this.editSlot = editSlot;
		}
		if (panel != null) {
			this.panel = panel;
		}
		if (schedule != null) {
			this.schedule = schedule;
		}
	}

	public String display() {
		if (schedule != null && panel != null) {
			String output = "<form action=\"/droidconcloud/schedule\" method=\"post\">"
					+ "<fieldset><legend>Slot</legend>"
					+ "<label for=\"title\">Title:</label> "
					+ "<input type=\"text\" name=\"title\" id=\"title\" value=\""
					+ (editSlot != null ? editSlot.getTitle() : "")
					+ "\" /><br/>"
					+ "<label for=\"description\">Description:</label> "
					+ "<input type=\"text\" name=\"description\" id=\"description\" value=\""
					+ (editSlot != null ? editSlot.getDescription() : "")
					+ "\" /><br/>"
					+ "<label for=\"speaker\">Speaker:</label> "
					+ "<input type=\"text\" name=\"speaker\" id=\"speaker\" value=\""
					+ (editSlot != null ? editSlot.getSpeaker() : "")
					+ "\" /><br/>"
					+ "<label for=\"alias\">Room alias:</label> "
					+ "<input type=\"text\" name=\"alias\" id=\"alias\" value=\""
					+ (editSlot != null ? editSlot.getRoomAlias() : "")
					+ "\" /><br/>"
					+ "<input type=\"hidden\" name=\"id\" value=\""
					+ schedule.getId()
					+ "\" />"
					+ "<input type=\"hidden\" name=\"panelId\" value=\""
					+ panel.getId().getId()
					+ "\" />"
					+ (editSlot != null ? "<input type=\"hidden\" name=\"slotId\" value=\""
							+ editSlot.getId().getId() + "\" />"
							: "")
					+ (editSlot == null ? "<input type=\"hidden\" name=\"action\" value=\"addSlot\" />"
							: "")
					+ (editSlot != null ? "<input type=\"hidden\" name=\"action\" value=\"editSlot\" />"
							: "")
					+ "<input type=\"submit\" value=\""
					+ (editSlot != null ? "edit" : "add")
					+ " slot\" /> "
					+ "<input type=\"submit\" name=\"action\" value=\"reset\" />"
					+ "</fieldset>" + "</form>";
			return output;
		} else {
			return "";
		}
	}

}
